﻿using System;
using System.Globalization;
using EpiNEXT.Core;

namespace EpiNEXT.Core.Validation.Functions
{
    public sealed class Years : DateDiffBase
    {
        public Years()
            : base()
        {

        }

        public override object Execute(Record record, params object[] parameters)
        {
            object result = base.Execute(record, parameters);

            if (result == null)
            {
                return result;
            }
            else
            {
                DateTime zeroTime = new DateTime(1, 1, 1);

                DateTime a = new DateTime(2007, 1, 1);
                DateTime b = new DateTime(2008, 1, 1);

                TimeSpan span = b - a;
                // because we start at year 1 for the Gregorian 
                // calendar, we must subtract a year here.
                int years = (zeroTime + span).Year - 1;

                return years;
            }
        }
    }
}
